// pages/my/my.js
let app = getApp()
let yuming = app.globalData.yuming
const request = require('../../config/request');
Page({
  ...request,
  /**
   * 页面的初始数据
   */
  data: {
    yuming: yuming,
    heights: "",
    title: '',
    list: [],
    kefu: '09173807093',
    jgweidu: 0,
    grweidu: 0,
    advise: [],
    yzshow: false,
    jinghe_id: '',
    scanNum:''
  },
  goyingji(){
    wx.navigateTo({
      url: '/page_other/yingjiguanli/yingjiguanli',
    })
  },
  // 修改密码
  xiugai() {
    wx.navigateTo({
      url: '/page_zhu/wangjimima/wangjimima?title=修改密码&state=1',
    })
  },
  getCishu() {
    wx.request({
      url: 'https://msion.86wky.com/shop/scan_shop_total',
      data: {
        shopId: wx.getStorageSync('shopId'),
      },
      header: {
        'Content-Type': 'application/x-www-form-urlencoded',
        Token: wx.getStorageSync('token'),
      },
      method: 'post',
      success: (res) => {
        this.setData({
          scanNum: res.data.data.scan_num,
        })
      },
    })
  },
  goyingjiss(){
    wx.navigateTo({
      url: '',
    })
  },
  yanzheng() {
    wx.showModal({
      title: '需要授权哦~',
      cancelText: '取消',
      confirmText: '确定',
      success: function (res) {
        if (res.confirm) {
          console.log("确定")
          wx.redirectTo({
            url: '/page_zhu/shou/shou?sta=0&url=pages/index/index',
          })
        } else {
          wx.navigateBack({
            delta: 0,
          })
          console.log("取消")
        }
      }
    })
  },
  // 经营信息
  xijing() {
    wx.navigateTo({
      url: '/page_one/xgdp/xgdp',
    })
  },
  // 签到
  qiandao() {
    wx.navigateTo({
      url: '/my_dian/qiandao/qiandao',
    })
  },
  getAdvise() {
    this.myRequest(yuming + 'Besall/public_adwords', {
      shopId: wx.getStorageSync('shopId'),
      alias: 'qs_home'
    }, 'POST').then(res => {
      if (res.data.code == 200) {
        this.setData({
          advise: res.data.data
        })
      }
    })
  },


  // 客服电话
  getKefuTel(){
    this.myRequest(yuming + 'Besall/unknown_phone',"POST").then((res)=>{
      console.log(res.data.data);
      this.setData({
        kefu:res.data.data
      })
    })
  },
  getcaoz() {
    this.myRequest(yuming + 'Jinghexincheng/jhxc_shopzhinan_list', {
      shopId: wx.getStorageSync('shopId')
    }, 'POST').then(res => {
      if (res.data.code == 200) {
        this.setData({
          caourl: res.data.data[0].fileurl
        })
      }
    })
  },
  // 动态
  dongt() {
    wx.navigateTo({
      url: '/page_two/beievlute/beievlute'
      // url: '/page_two/bossquan/bossquan?title=区域社群',
    })
  },
  // 关注
  guanzhu() {
    wx.navigateTo({
      url: '/page_two/tousu/tousu'
      // url: '/my_other/guanzhu/guanzhu',
    })
  },
  // 信用等级
  xinyong() {
    wx.navigateTo({
      url: '/page_other/saomnum/saomnum',
    })
  },
  // 数据
  shuju() {
    var that = this
    this.myRequest(yuming + 'Besall/userAndShopInfo', {
      shopId: wx.getStorageSync('shopId')
    }, 'POST').then(res => {
      that.setData({
        grxx: res.data.shop,
        mobile: res.data.shop.mobile,
        shopType: res.data.shop.shopType,
        avatar: res.data.shop.shopLogo,
        shopBosscircle: res.data.shopEvaluate, //动态
        shopCoverfollow: res.data.shopCoverfollow, //粉丝
        shopCredit: res.data.shopCredit, //等级
        shopfollow: res.data.ShopComplaint, //动态
        shopNotice: res.data.shopNotice
      })
    })
  },
  // 添加分店
  tianjia() {
    // addfd
    wx.navigateTo({
      url: '/page_zhu/zhuce/zhuce?title=添加分店&mobile=' + this.data.mobile + "&shopType=" + this.data.shopType,
    })
  },
  // 信息录入
  xinxilr(e) {
    wx.navigateTo({
      url: '/my_other/xinxilr/xinxilr',
    })
  },
  // 菜单
  jin(e) {
    // foodState  0未开通，1已开通，
    // isRenew    true为需要续费
    // isAsker     true 为已支付-开通申请/续费申请
    var index = (e.currentTarget.dataset.index) + 1
    var url = e.currentTarget.dataset.url
    var length = this.data.list.length
    var open = e.currentTarget.dataset.open
    if (this.data.jinghe_id == 176) {
      if (index == length - 1) {
        let url = this.data.caourl
        var s = url.lastIndexOf(".")
        var b = url.substring(s + 1) //下划线之后
        console.log(2121)
        console.log(b)
        if (b == 'jpg' || b == 'jpeg' || b == 'png') {
          wx.previewImage({
            urls: [url]
          })
        } else {
          wx.showLoading({
            title: '正在打开中',
          })
          wx.downloadFile({
            url: url,
            success(res) {
              console.log(res)
              var filePath = res.tempFilePath
              console.log(filePath)
              wx.openDocument({
                filePath: filePath,
                fileType: b,
                success: function (res) {
                  wx.hideLoading({
                    success: (res) => {},
                  })
                },
                fail(err) {
                  wx.hideLoading({
                    success: (res) => {},
                  })
                  wx.showToast({
                    title: '打开失败',
                    icon: 'none'
                  })
                }
              })


            }
          })

        }
      }
    }
    let styid = wx.getStorageSync('stryId')
    if (this.data.jinghe_id != 176 && styid == 6) {
      if (index == length - 1) {
        let url = this.data.caourl
        var s = url.lastIndexOf(".")
        var b = url.substring(s + 1) //下划线之后
        console.log(2121)
        console.log(b)
        if (b == 'jpg' || b == 'jpeg' || b == 'png') {
          wx.previewImage({
            urls: [url]
          })
        } else {
          wx.showLoading({
            title: '正在打开中',
          })
          wx.downloadFile({
            url: url,
            success(res) {
              console.log(res)
              var filePath = res.tempFilePath
              console.log(filePath)
              wx.openDocument({
                filePath: filePath,
                fileType: b,
                success: function (res) {
                  wx.hideLoading({
                    success: (res) => {},
                  })
                },
                fail(err) {
                  wx.hideLoading({
                    success: (res) => {},
                  })
                  wx.showToast({
                    title: '打开失败',
                    icon: 'none'
                  })
                }
              })


            }
          })

        }
      }
    }
    if(open){
      wx.showToast({
        title: '此功能暂未开放',
        icon:'error'
      })
      return
    }
    if (wx.getStorageSync('stryId') == 13) {
      // if (index == 9) {
      //   console.log(this.data.grxx.foodState)
      //   if (this.data.grxx.foodState == 0) {
      //     console.log(11)
      //     wx.navigateTo({
      //       url: '/my_dian/sqdc/sqdc?title=申请点餐码',
      //     })
      //   } else {
      //     console.log(22)
      //     wx.navigateTo({
      //       url: '/my_dian/dianindex/dianindex',
      //     })
      //   }
      // } else {
        wx.navigateTo({
          url: url,
        })
      // }
    } else {
      wx.navigateTo({
        url: url,
      })
    }
    if (index == length) {
      wx.makePhoneCall({
        phoneNumber: this.data.kefu
      })
    }
  },
  //切换店铺
  qiehuan() {
    wx.navigateTo({
      url: '/page_zhu/xzdp/xzdp?mobile=' + this.data.mobile,
    })
  },
  // 退出登录
  tui() {
    wx.showModal({
      title: '您确定要退出吗？',
      cancelText: '取消',
      confirmText: '确定',
      success: function (res) {
        if (res.confirm) {
          wx.clearStorage({
            success: (res) => {},
          })
          wx.reLaunch({
            url: '/page_zhu/login/login',
          })
          console.log("确定");
          // wx.setStorageSync('shopId', '');
          // wx.setStorageSync('sonType', '');
          // wx.setStorageSync('subId', '');
          // wx.setStorageSync('token', '');
          // wx.setStorageSync('wsdToken', '');
          // wx.setStorageSync('sign', '');
          // wx.setStorageSync('ima', '');
          // wx.setStorageSync('yqsign', '');
          // wx.setStorageSync('spsign', '');
          // wx.setStorageSync('qita', '');
        } else {
          console.log("取消");
        }
      }
    })
  },
  goweekOrder(){
    wx.navigateTo({
      url: '/page_two/weekmenu/weekmenu?v=1',
    })
  },
  goweekOrderT(){
    wx.navigateTo({
      url: '/page_two/weekmenu/weekmenu?v=2',
    })
  },
  goweekOrderTTT(){
    wx.navigateTo({
      url: '/page_two/tableware/tableware',
    })
  },
  goweekYanxiJIlu(e){
    console.log(e.currentTarget.dataset.typemode);
    const aaaBBB = e.currentTarget.dataset.typemode
    wx.navigateTo({
      url: '/page_two/yanXijilu/yanXijilu?modeType=' + aaaBBB,
    })
  },


  // 消息
  xiaoxi() {
    wx.switchTab({
      url: '/pages/xiaoxi/xiaoxi',
    })
    // wx.navigateTo({
    //   url: '/page_one/jianguan/jianguan',
    // })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      heights: wx.getMenuButtonBoundingClientRect().top + 5,
      jinghe_id: wx.getStorageSync('jinghe_id')
    })
    const hangyeID =wx.getStorageSync('stryId')
    wx.hideTabBar();
    this.getAdvise();
    this.getcaoz()
    this.getCishu()
    if (wx.getStorageSync('stryId') == 6) {
      this.setData({
        list: [
          // {
          //   img: yuming + 'static/applet/images/my/xgdp.png',
          //   tit: '基本信息',
          //   url: '/page_one/xgdp/xgdp?title='
          // },
          // {
          //   img: yuming + 'static/applet/images/my/ygzz.png',
          //   tit: '从业人员',
          //   url: '/page_one/congye/congye?title=从业人员'
          // },
          // {
          //   img: yuming + 'static/applet/images/index/fenlei.png',
          //   tit: '药政学习',
          //   url: '/page_two/guanlzd/guanlzd?title=药政学习'
          // },
          // {
          //   img: yuming + 'static/applet/images/my/jgxc.png',
          //   tit: '检查记录',
          //   url: '/my_other/hfjg/hfjg?title=检查记录'
          // },
          // {
          //   img: yuming + 'static/applet/images/tubiao/choujian.png',
          //   tit: '抽检公示',
          //   url: '/page_other/choujian/choujian?title=抽检公示'
          // },
          // {
          //   img: yuming + 'static/applet/images/tubiao/fengxian.png',
          //   tit: '风险等级',
          //   url: '/page_other/fengxian/fengxian?title=风险等级'
          // },
          // {
          //   img: yuming + 'static/applet/images/tubiao/jingying.png',
          //   tit: '经营数据',
          //   url: '/page_other/shuju/shuju?title=经营数据'
          // },
          // {
          //   img: yuming + 'static/applet/images/my/zzhgl.png',
          //   tit: '账号管理',
          //   url: '/my_other/zzhgl/zzhgl?title=账号管理'
          // },
          // {
          //   img: yuming + 'static/applet/images/my/bgt.png',
          //   tit: '曝光台',
          //   url: '/my_other/bgt/bgt?title=曝光台'
          // },

          // {
          //   img: yuming + 'static/applet/images/my/jybx.png',
          //   tit: '经营保险',
          //   url: '/my_other/jybx/jybx?title=经营保险'
          // },
          // {
          //   img: yuming + 'static/applet/images/my/gongshi.png',
          //   tit: '公示牌',
          //   url: '/page_two/study/study?title=公示牌'
          // },
          // {
          //   img: yuming + 'static/applet/images/my/about.png',
          //   tit: '店铺排行',
          //   url: '/my_other/dtphb/dtphb?title=店铺排行'
          // },
          // {
          //   img: yuming + 'static/applet/images/my/mianfei.png',
          //   tit: '兑换专区',
          //   url: '/my_dian/dui/dui?title=兑换专区'
          // },
          {
            img: yuming + 'static/applet/images/tubiao/change.png',
            tit: '修改手机号',
            url: '/page_zhu/wangjimima/wangjimima?title=修改手机号&state=11'
          },
          {
            img: yuming + 'static/applet/images/tubiao/change.png',
            tit: '修改密码',
            url: '/page_zhu/wangjimima/wangjimima?title=修改密码&state=1'
          },
          {
            img: yuming + 'static/applet/images/tubiao/about.png',
            tit: '关于平台',
            url: '/page_zhu/xieyi/xieyi?title=关于平台&state=about&st=0'
          },
          {
            img: yuming + 'static/applet/images/tubiao/helpcenter.png',
            tit: '帮助中心',
            url: '/my_other/bangzzx/bangzzx?title=帮助中心'
          },
          {
            img: yuming + 'static/applet/images/tubiao/caozuo.png',
            tit: '操作指南',
          },
          {
            img: yuming + 'static/applet/images/my/kf.png',
            tit: '在线客服'
          },
        ],
      })
    } else if (wx.getStorageSync('stryId') == 13 ||  hangyeID == 7 || hangyeID == 13 || hangyeID == 16 || hangyeID ==17 || hangyeID ==20 || hangyeID ==21 || hangyeID ==22 || hangyeID ==23 || hangyeID ==24 || hangyeID ==25 || hangyeID ==26 || hangyeID ==27 || hangyeID ==28 || hangyeID ==28 || hangyeID ==33) {
      this.setData({
        list: [
      
          // {
          //   img: yuming + 'static/applet/images/my/xgdp.png',
          //   tit: '经营信息',
          //   url: '/page_one/xgdp/xgdp?title=经营信息'
          // },
          // {
          //   img: yuming + 'static/applet/images/my/ygzz.png',
          //   tit: '从业人员',
          //   url: '/page_one/congye/congye?title=从业人员'
          // },
          {
            img: yuming + 'static/applet/images/my/jgxc.png',
            tit: '检查公示',
            url: '/my_other/hfjg/hfjg?title=检查公示'
          },
          {
            img: yuming + 'static/applet/images/tubiao/choujian.png',
            tit: '抽检公示',
            url: '/page_other/choujian/choujian?title=抽检公示'
          },
          {
            img: yuming + 'static/applet/images/tubiao/fengxian.png',
            tit: '风险等级',
            url: '/page_other/fengxian/fengxian?title=风险等级'
          },
          {
            img: yuming + 'static/applet/images/tubiao/jingying.png',
            tit: '经营数据',
            // url: '/page_other/shuju/shuju?title=经营数据'
            noOpen:true
          },
          // {
          //   img: yuming + 'static/applet/images/my/bgt.png',
          //   tit: '曝光台',
          //   url: '/my_other/bgt/bgt?title=曝光台'
          // },
          {
            img: yuming + 'static/applet/images/my/zzhgl.png',
            tit: '账号管理',
            url: '/my_other/zzhgl/zzhgl?title=账号管理'
          },
          {
            img: yuming + 'static/applet/images/my/sqdcm.png',
            tit: '点餐码',
            url: '/my_dian/sqdc/sqdc?title=申请点餐码',
            noOpen:true
          },
          {
            img: yuming + 'static/applet/images/my/mianfei.png',
            tit: '兑换专区',
            url: '/my_dian/dui/dui?title=兑换专区'
          },
          {
            img: yuming + 'static/applet/images/my/jybx.png',
            tit: '经营保险',
            url: '/my_other/jybx/jybx?title=经营保险',
            noOpen:true
          },
          {
            img: yuming + 'static/applet/images/my/about.png',
            tit: '店铺排行',
            url: '/my_other/dtphb/dtphb?title=店铺排行'
          },
          {
            img: yuming + 'static/applet/images/my/gongshi.png',
            tit: '公示牌',
            url: '/page_two/study/study?title=公示牌'
          },
          {
            img: yuming + 'static/applet/images/tubiao/about.png',
            tit: '关于平台',
            url: '/page_zhu/xieyi/xieyi?title=关于平台&state=about'
          },
          {
            img: yuming + 'static/applet/images/tubiao/helpcenter.png',
            tit: '帮助中心',
            url: '/my_other/bangzzx/bangzzx?title=帮助中心'
          },
          {
            img: yuming + 'static/applet/images/my/kf.png',
            tit: '在线客服'
          },
        ],
      })
    } else {
      this.setData({
        list: [{
            img: yuming + 'static/applet/images/my/xgdp.png',
            tit: '经营信息',
            url: '/page_one/xgdp/xgdp?title=经营信息'
          },
          {
            img: yuming + 'static/applet/images/my/ygzz.png',
            tit: '从业人员',
            url: '/page_one/congye/congye?title=从业人员'
          },
          {
            img: yuming + 'static/applet/images/my/jgxc.png',
            tit: '检查公示',
            url: '/my_other/hfjg/hfjg?title=检查公示'
          },
          {
            img: yuming + 'static/applet/images/tubiao/choujian.png',
            tit: '抽检公示',
            url: '/page_other/choujian/choujian?title=抽检公示'
          },
          {
            img: yuming + 'static/applet/images/tubiao/fengxian.png',
            tit: '风险等级',
            url: '/page_other/fengxian/fengxian?title=风险等级'
          },
          {
            img: yuming + 'static/applet/images/tubiao/jingying.png',
            tit: '经营数据',
            // url: '/page_other/shuju/shuju?title=经营数据'
            noOpen:true
          },
          {
            img: yuming + 'static/applet/images/my/bgt.png',
            tit: '曝光台',
            url: '/my_other/bgt/bgt?title=曝光台'
          },
          {
            img: yuming + 'static/applet/images/my/zzhgl.png',
            tit: '账号管理',
            url: '/my_other/zzhgl/zzhgl?title=账号管理'
          },
          {
            img: yuming + 'static/applet/images/my/mianfei.png',
            tit: '兑换专区',
            url: '/my_dian/dui/dui?title=兑换专区'
          },
          // {
          //   img: yuming + 'static/applet/images/my/jybx.png',
          //   tit: '经营保险',
          //   // url: '/my_other/jybx/jybx?title=经营保险'
          // },
          {
            img: yuming + 'static/applet/images/my/about.png',
            tit: '店铺排行',
            url: '/my_other/dtphb/dtphb?title=店铺排行'
          },
          {
            img: yuming + 'static/applet/images/my/gongshi.png',
            tit: '公示牌',
            url: '/page_two/study/study?title=公示牌'
          },
          {
            img: yuming + 'static/applet/images/tubiao/about.png',
            tit: '关于平台',
            url: '/page_zhu/xieyi/xieyi?title=关于平台&state=about'
          },
          {
            img: yuming + 'static/applet/images/tubiao/helpcenter.png',
            tit: '帮助中心',
            url: '/my_other/bangzzx/bangzzx?title=帮助中心'
          },
          {
            img: yuming + 'static/applet/images/my/kf.png',
            tit: '在线客服'
          },
        ],
      })
    }
    // if (wx.getStorageSync('token') == '') {
    //   this.setData({
    //     yzshow: true
    //   })
    // }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },
  // 红点
  hongdian() {
    var that = this
    this.myRequest(yuming + 'besall/messageHongdian', {
      shopId: wx.getStorageSync('shopId'),
    }, "POST").then(res => {
      console.log(res)
      that.setData({
        jgweidu: res.data.data.jg_count,
        grweidu: res.data.data.gr_count,
      })
    })
  },
  fqmp() {
    wx.showToast({
      title: '维护中，敬请期待',
      icon: 'none'
    })
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.shuju()
    this.hongdian()
    this.getCishu()
    this.getKefuTel()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },
})